#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define MAZLED0         12
#define MAZLED1         13
#define MAZKEY0         9

#define LED_ON          1
#define LED_OFF         0

#define KEY_DOWN        0
#define KEY_UP          1

static int status = LED_OFF;

static void IRAM_ATTR gpio_isr_handler(void* arg)
{
        if(LED_OFF == status)
        {
                gpio_set_level(MAZLED0, LED_ON);
                gpio_set_level(MAZLED1, LED_ON);
                status = LED_ON;
        }
        else
        {
                gpio_set_level(MAZLED0, LED_OFF);
                gpio_set_level(MAZLED1, LED_OFF);
                status = LED_OFF;
        }

}

void app_main(void)
{
        gpio_reset_pin(MAZLED0);
        gpio_set_direction(MAZLED0, GPIO_MODE_OUTPUT);

        gpio_reset_pin(MAZLED1);
        gpio_set_direction(MAZLED1, GPIO_MODE_OUTPUT);

        gpio_reset_pin(MAZKEY0);
        gpio_set_direction(MAZKEY0, GPIO_MODE_INPUT);
        gpio_set_intr_type(MAZKEY0, GPIO_INTR_NEGEDGE);

        gpio_install_isr_service(0);
        gpio_isr_handler_add(MAZKEY0, gpio_isr_handler, (void*) MAZKEY0);

        while(1)
        {
                vTaskDelay(1000);
        }
}
